package org.microservice.system.service.impl;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.microservice.system.dao.DepartmentLeadersDao;
import org.microservice.system.entity.DepartmentLeadersEntity;
import org.microservice.system.service.DepartmentLeadersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: 齐丹枫
 * Date: 2018/7/12
 * Time: 9:56
 * To change this template use File | Settings | File Templates.
 * Description:
 */
@Service
public class DepartmentLeadersServiceImpl
        extends ServiceImpl<DepartmentLeadersDao,DepartmentLeadersEntity>
        implements DepartmentLeadersService{


    @Autowired
    private DepartmentLeadersDao departmentLeadersDao;

    @Override
    public void saveOrUpdate(int departmentId, List<Integer> userIds) {

        Map map =new HashMap<String,Integer>();
        map.put("department_id",departmentId);
        departmentLeadersDao.deleteByMap(map);
        for (int i: userIds
             ) {
            DepartmentLeadersEntity departmentLeadersEntity = new DepartmentLeadersEntity(departmentId, i);
            this.insert(departmentLeadersEntity);
        }

    }
}
